package com.guigu.qingcheng.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.guigu.qingcheng.mapper.TbReturnOrderItemMapper;
import com.guigu.qingcheng.pojo.TbReturnOrderItem;
import com.guigu.qingcheng.service.TbReturnOrderItemService;
import com.guigu.qingcheng.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;


/**
*
* @author Jiang
* @date 2020/07/31
*/
@Service
public class TbReturnOrderItemServiceImpl implements TbReturnOrderItemService {
    @Autowired(required = false)
    private TbReturnOrderItemMapper tbReturnOrderItemMapper;



    @Override
    public List<TbReturnOrderItem> queryAll() {
        List<TbReturnOrderItem> tbReturnOrderItem = tbReturnOrderItemMapper.selectAll();
            return tbReturnOrderItem;
    }

    @Override
    public PageUtil<TbReturnOrderItem> findListAll(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        Page<TbReturnOrderItem> pages = (Page<TbReturnOrderItem>) tbReturnOrderItemMapper.selectAll();
        PageUtil<TbReturnOrderItem> pageUtil=new PageUtil<>();
        pageUtil.setRows(pages.getResult());
        pageUtil.setTotal(pages.getTotal());
        return pageUtil;
    }


    @Override
    public PageUtil<TbReturnOrderItem> pageQueryByAll(Integer pageNum, Integer pageSize, TbReturnOrderItem tbReturnOrderItem) {

        Example example=new Example(TbReturnOrderItem.class);
        Example.Criteria criteria = example.createCriteria();
        // TODO 待实现 重新实现判断参数

        if(!StringUtils.isEmpty(tbReturnOrderItem.getId())){
            criteria.andEqualTo("id",tbReturnOrderItem.getId());
        }
//        if(!StringUtils.isEmpty(tbReturnOrderItem.get)){
//           criteria.andLike("name","%"+tbReturnOrderItem.getName()+"%");
//        }
        PageHelper.startPage(pageNum,pageSize);
        Page<TbReturnOrderItem> pages = (Page<TbReturnOrderItem>) tbReturnOrderItemMapper.selectByExample(example);
        PageUtil<TbReturnOrderItem> pageUtil=new PageUtil<>();
        pageUtil.setRows(pages.getResult());
        pageUtil.setTotal(pages.getTotal());
        return pageUtil;
     }


    @Override
    public boolean saveTbReturnOrderItem(TbReturnOrderItem tbReturnOrderItem) {
        int insert = tbReturnOrderItemMapper.insert(tbReturnOrderItem);
        if(insert>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean updateTbReturnOrderItem(TbReturnOrderItem tbReturnOrderItem) {
        int i = tbReturnOrderItemMapper.updateByPrimaryKeySelective(tbReturnOrderItem);
        if(i>0){
            return true;
        }
        return false;
    }


    @Override
    public boolean deleteById(Integer id) {
        int i = tbReturnOrderItemMapper.deleteByPrimaryKey(id);
        if(i>0){
            return true;
        }
        return false;
    }

    @Override
    public TbReturnOrderItem findById(Integer id) {
        TbReturnOrderItem tbReturnOrderItem = tbReturnOrderItemMapper.selectByPrimaryKey(id);
        return tbReturnOrderItem;
    }
}
